package com.hangzhou.welbeing.welbeinginstrument.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.adapter.ReleaseSimilarProfilePageFocusedHeaderAdapter;
import com.hangzhou.welbeing.welbeinginstrument.adapter.SimilarProfilePageFocusedAdapter;
import com.hangzhou.welbeing.welbeinginstrument.base.MyApplication;
import com.hangzhou.welbeing.welbeinginstrument.bean.ClickcollectBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.CommentsBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.EventBusBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.EventZanBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.ExposePostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.PostCommentsBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.PraiseBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.SimilarProfilePageFocusedHeaderBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.TipOffPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.deleteOthersBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.utils.DialogUtil;
import com.hangzhou.welbeing.welbeinginstrument.utils.OnItemSelectedListener;
import com.hangzhou.welbeing.welbeinginstrument.utils.UIUtils;
import com.hangzhou.welbeing.welbeinginstrument.utils.Utils;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import okhttp3.Call;
import okhttp3.Response;

import static com.lzy.imagepicker.ImagePicker.TAG;

/**
 * 杭州惟君医疗科技有限公司09
 * Created by 20433 on 2018/2/2
 */

public class ReleaseSimilarProfilePageFocusedActivity extends Activity implements View.OnClickListener{

    @Bind(R.id.activit_release_similar_profile_page_focused_iv_return)
    ImageView activitReleaseSimilarProfilePageFocusedIvReturn;
    @Bind(R.id.activit_release_similar_profile_page_focused_iv_right)
    ImageView activitReleaseSimilarProfilePageFocusedIvRight;
    @Bind(R.id.activit_release_similar_profile_page_focused_xRecyclerView)
    XRecyclerView activitReleaseSimilarProfilePageFocusedXRecyclerView;
    @Bind(R.id.activit_release_similar_profile_page_focused_iv_praise)
    ImageView activitReleaseSimilarProfilePageFocusedIvPraise;
    @Bind(R.id.activit_release_similar_profile_page_focused_tv_praise_bumber)
    TextView activitReleaseSimilarProfilePageFocusedTvPraiseBumber;
    @Bind(R.id.activit_release_similar_profile_page_focused_rl_praise)
    RelativeLayout activitReleaseSimilarProfilePageFocusedRlPraise;
    @Bind(R.id.activit_release_similar_profile_page_focused_iv_comments)
    ImageView activitReleaseSimilarProfilePageFocusedIvComments;
    @Bind(R.id.activit_release_similar_profile_page_focused_tv_comments_bumber)
    TextView activitReleaseSimilarProfilePageFocusedTvCommentsBumber;
    @Bind(R.id.activit_release_similar_profile_page_focused_rl_comments)
    RelativeLayout activitReleaseSimilarProfilePageFocusedRlComments;
    @Bind(R.id.activit_release_similar_profile_page_focused_iv_favorite)
    ImageView activitReleaseSimilarProfilePageFocusedIvFavorite;
    @Bind(R.id.activit_release_similar_profile_page_focused_tv_favorite_bumber)
    TextView activitReleaseSimilarProfilePageFocusedTvFavoriteBumber;
    @Bind(R.id.activit_release_similar_profile_page_focused_rl_favorite)
    RelativeLayout activitReleaseSimilarProfilePageFocusedRlFavorite;
    @Bind(R.id.activit_release_similar_profile_page_focused_ll_is_visition)
    LinearLayout activitReleaseSimilarProfilePageFocusedLlIsVisition;
    @Bind(R.id.activit_release_similar_profile_page_focused_bt_sand_commentaries)
    Button activitReleaseSimilarProfilePageFocusedBtSandCommentaries;
    @Bind(R.id.activit_release_similar_profile_page_focused_et_commentaries_content)
    EditText activitReleaseSimilarProfilePageFocusedEtCommentariesContent;
    @Bind(R.id.activit_release_similar_profile_page_focused_ll_commentaries)
    RelativeLayout activitReleaseSimilarProfilePageFocusedLlCommentaries;
    private RecyclerView header_recyclerView;

    private List<PostCommentsBean.DataBean> mlist = new ArrayList<>();
    private SimilarProfilePageFocusedAdapter similarProfilePageFocusedAdapter;

    private int p = 1 ;
    private boolean flag = true;
    private int col;
    private int lCount;
    private int datalist1;
    private int datacount;
    private int lstate;
    private LinearLayout ll_wei_xin;
    private LinearLayout ll_qq;
    private LinearLayout ll_wei_bo;
    private LinearLayout ll_tip_off;
    private LinearLayout ll_delect;
    private TextView tv_cancel;
    private PopupWindow popupWindow;
    int mWidth;
    private List<String> datalist;
    private String po_id;
    private String po_name;
    private String addtime;
    private String video;
    private String vpic;
    private String content;
    private String cat_id;
    private String cus_id;
    private String cus_name;
    private String cus_logo;
    private String count;
    private int hits_like;
    private int lstate1;
    private int col1;
    private int state;
    private int lCount1;
    private List<PostCommentsBean.DataBean> data = new ArrayList<>();
    private int posts_deleted_id;
    private String posts_deleted;
    private boolean flag_01 = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(32);
        setContentView(R.layout.activit_release_similar_profile_page_focused);
        ButterKnife.bind(this);
       // ButterKnife.bind(ReleaseSimilarProfilePageFocusedActivity.this);
        Utils.setStatusBar(this, false, false);
        Utils.setStatusTextColor(false, this);
        //EventBus.getDefault().register(this);
        Intent intent = getIntent();
        posts_deleted = intent.getStringExtra("posts_deleted");
        posts_deleted_id = intent.getIntExtra("posts_deleted_id",0);

        po_id = intent.getStringExtra("po_id");
        po_name = intent.getStringExtra("po_name");
        addtime = intent.getStringExtra("addtime");
        video = intent.getStringExtra("video");
        vpic = intent.getStringExtra("vpic");
        content = intent.getStringExtra("content");
        cat_id = intent.getStringExtra("cat_id");
        cus_id = intent.getStringExtra("cus_id");
        cus_name = intent.getStringExtra("cus_name");
        cus_logo = intent.getStringExtra("cus_logo");
        count = intent.getStringExtra("count");
        hits_like = intent.getIntExtra("hits_like",0);
        lstate1 = intent.getIntExtra("lstate",0);
        col1 = intent.getIntExtra("col",0);
        state = intent.getIntExtra("state",0);
        lCount1 = intent.getIntExtra("lCount",0);


        datalist = (List<String>) intent.getSerializableExtra("po_url");
        //Log.e(TAG,"praiseParseNetworkResponse===222=========>"+datalist.size());
        if(datalist == null){
            finish();
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
        col1 = col;
        try {
            datacount = Integer.parseInt(count);
            activitReleaseSimilarProfilePageFocusedTvCommentsBumber.setText(datacount +"");
        } catch (Exception e) {}
        if(col == 0){  //没收藏
            activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang);
        }else{  //收藏
            activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang_01);
        }
        activitReleaseSimilarProfilePageFocusedTvFavoriteBumber.setText(lCount +"");
       // Log.e(TAG,"praiseParseNetworkResponse==555 =lstate=========>"+lstate1);
        if(lstate1 == 0){
            activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_05);
        }else{
            activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_10);
        }
        activitReleaseSimilarProfilePageFocusedTvPraiseBumber.setText(hits_like+"");
        activitReleaseSimilarProfilePageFocusedLlCommentaries.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int heightDiff = activitReleaseSimilarProfilePageFocusedLlCommentaries.getRootView().getHeight() - activitReleaseSimilarProfilePageFocusedLlCommentaries.getHeight();
                if (heightDiff > UIUtils.dip2Px(200)){  // 显示

                }else{  //不显示
                    activitReleaseSimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                    activitReleaseSimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                }
            }
        });
     //   mlist = new ArrayList<>(); //TODO 等下删掉
        LinearLayoutManager layoutManager =   new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setLayoutManager(layoutManager);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setArrowImageView(R.mipmap.iconfont_downgrey);
        View headerview = LayoutInflater.from(this).inflate(R.layout.fragment_similar_profile_page_focused_header,  (ViewGroup)findViewById(android.R.id.content),false);
        findHeaderView(headerview);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.addHeaderView(headerview);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setPullRefreshEnabled(false);  //TODO 禁止下拉刷新完毕
        activitReleaseSimilarProfilePageFocusedXRecyclerView.getDefaultFootView().setNoMoreHint("就这么多了");

        activitReleaseSimilarProfilePageFocusedXRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                flag = true;
                loadCommentsData(po_id,p);
            }

            @Override
            public void onLoadMore() {
                p++;
                flag = false;
                loadCommentsData(po_id,p);

            }
        });
        activitReleaseSimilarProfilePageFocusedIvReturn.setOnClickListener(this);
        activitReleaseSimilarProfilePageFocusedIvRight.setOnClickListener(this);
        activitReleaseSimilarProfilePageFocusedRlPraise.setOnClickListener(this);
        activitReleaseSimilarProfilePageFocusedRlComments.setOnClickListener(this);
        activitReleaseSimilarProfilePageFocusedRlFavorite.setOnClickListener(this);
        activitReleaseSimilarProfilePageFocusedBtSandCommentaries.setOnClickListener(this);

        similarProfilePageFocusedAdapter = new SimilarProfilePageFocusedAdapter(this);
        activitReleaseSimilarProfilePageFocusedXRecyclerView.setAdapter(similarProfilePageFocusedAdapter);
        similarProfilePageFocusedAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view) {}
            @Override
            public void onItemFirstButtonClick(View v, int position) {
//                Intent intent = new Intent(ReleaseSimilarProfilePageFocusedActivity.this,AllCommentsActivity.class);
//                intent.putExtra("addtime", data.get(position).addtime);
//                intent.putExtra("content", data.get(position).content);
//                intent.putExtra("cus_logo", data.get(position).cus_logo);
//                intent.putExtra("cus_name", data.get(position).cus_name);
//                intent.putExtra("cus_id", data.get(position).cus_id);
//                intent.putExtra("id", data.get(position).id);
//                startActivity(intent);
//                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            }
        });


        loadCommentsData(po_id,p);
        initData();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activit_release_similar_profile_page_focused_iv_return:
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                break;
            case R.id.activit_release_similar_profile_page_focused_iv_right:  //分享
                share();
                break;
            case R.id.activit_release_similar_profile_page_focused_rl_praise:  //点赞
                giveLike();
                break;
            case R.id.activit_release_similar_profile_page_focused_rl_comments: //评论
                activitReleaseSimilarProfilePageFocusedLlIsVisition.setVisibility(View.GONE);
                activitReleaseSimilarProfilePageFocusedLlCommentaries.setVisibility(View.VISIBLE);
                break;
            case R.id.activit_release_similar_profile_page_focused_rl_favorite:  //收藏
//                if(col == 0){  //没收藏
//                    activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang);
//                }else{  //收藏了
//                    activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang_01);
//                }
                clickcollect(po_id);
                break;
            case R.id.activit_release_similar_profile_page_focused_bt_sand_commentaries: //发送评论
                String EtCommentariesContent =  activitReleaseSimilarProfilePageFocusedEtCommentariesContent.getText().toString().trim();
                if(!TextUtils.isEmpty(EtCommentariesContent)){
                    submitComments(EtCommentariesContent);
                }else{
                    Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"请输入您的评论",Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.layout_similar_profile_page_focused_popupwindow_style_ll_wei_xin: //微信
                OnekeyShare oks = new OnekeyShare();

                if( datalist != null  && datalist.size() > 0){
                    oks.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + datalist.get(0) + "");
                }else{
                    oks.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + vpic + "");
                }
                oks.setTitleUrl("http://oop.welbeing.cn/admin.php/Posts/share?po_id=" +po_id + "");
                oks.setText(content);
                oks.setTitle(po_name);

                oks.setPlatform(Wechat.NAME);
                oks.show(this);
                popupWindow.dismiss();
                break;
            case R.id.layout_similar_profile_page_focused_popupwindow_style_ll_qq:  //qq
                OnekeyShare oks_01 = new OnekeyShare();

                if( datalist != null  && datalist.size() > 0){
                    oks_01.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + datalist.get(0) + "");
                }else{
                    oks_01.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + vpic + "");
                }
                oks_01.setTitleUrl("http://oop.welbeing.cn/admin.php/Posts/share?po_id=" +po_id + "");
                oks_01.setText(content);
                oks_01.setTitle(po_name);

                oks_01.setPlatform(QQ.NAME);
                oks_01.show(this);
                popupWindow.dismiss();
                break;
            case R.id.layout_similar_profile_page_focused_popupwindow_style_ll_wei_bo:  //微博
                OnekeyShare oks_02 = new OnekeyShare();


                if( datalist != null  && datalist.size() > 0){
                    oks_02.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + datalist.get(0) + "");
                }else{
                    oks_02.setImageUrl("http://oop.welbeing.cn/Public/Uploads/" + vpic + "");
                }
                oks_02.setTitleUrl("http://oop.welbeing.cn/admin.php/Posts/share?po_id=" +po_id + "");
                oks_02.setText(content);
                oks_02.setTitle(po_name);

                oks_02.setPlatform(SinaWeibo.NAME);
                oks_02.show(this);
                popupWindow.dismiss();
                break;
            case R.id.layout_similar_profile_page_focused_popupwindow_style_ll_tip_off:  //举报
                SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
                String user_id = sp.getString("user_id","");
                if(user_id.equals(cus_id)){
                    Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"不能举报自己",Toast.LENGTH_LONG).show();
                }else {
                    showDialog();
                  popupWindow.dismiss();

                }
                break;
            case R.id.layout_similar_profile_page_focused_popupwindow_style_ll_delect:  //删除
                SharedPreferences sp_01 = getSharedPreferences("second_app_internal_data", 0);
                String user_id_01 = sp_01.getString("user_id","");
                String tel = sp_01.getString("tel","");
                if(!TextUtils.isEmpty(posts_deleted.toString().trim())){ //todo 获取到帖子的识别码

                    if(tel.equals("15268550214")){  // TODO 管理员权限
                        if(user_id_01.equals(cus_id)){  //todo 删除自己的贴子
                            flag_01 = true;
                            Log.e(TAG,"praiseParseNetworkResponse===222=555===删除自己的贴子====>"+cus_id);
                            tipOffPost();
                        }else{  // todo  删除的不是自己的帖子
                            flag_01 = false;
                            Log.e(TAG,"praiseParseNetworkResponse===222=555===删除的不是自己的帖子====>"+cus_id);
                            tipOffPost();
                        }
                    }else {
                        if(user_id_01.equals(cus_id)){ //todo 删除自己的贴子
                            flag_01 = true;
                            tipOffPost();
                        }else{  // todo 不能删除别人的帖子
                            Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"删除是不被允许的",Toast.LENGTH_SHORT).show();
                        }
                    }

                }else{  //todo 未获取到帖子的识别码
                    Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"删除失败",Toast.LENGTH_SHORT).show();
                }


            case R.id.layout_similar_profile_page_focused_popupwindow_style_tv_cancel: //取消
                popupWindow.dismiss();
                break;
        }
    }
    /**
     * @desc 举报弹框
     * */
    private void initData() {
        DisplayMetrics dm = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);
        mWidth = dm.widthPixels;
    }
    private OnItemSelectedListener onIllegalListener = new OnItemSelectedListener() {
        @Override
        public void getSelectedItem(String content) {
            //Toast.makeText(SimilarProfilePageFocusedActivity.this, content, Toast.LENGTH_SHORT).show();
            exposePost(po_id,content);
        }
    };
    /**
     * @desc 加载评论数据
     * @param po_id
     * @param p */
    private void loadCommentsData(final String po_id, int p) {
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.POST_COMMENTS)
                .addParams("po_id", po_id)
                .addParams("p", p+"")
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                      //  Log.e(TAG,"praiseParseNetworkResponse===222=========>"+praiseParseNetworkResponse);
                        final PostCommentsBean postCommentsBean =  gson.fromJson(praiseParseNetworkResponse,PostCommentsBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(postCommentsBean.errorCode == 200){
                                    final List<PostCommentsBean.DataBean> databean = postCommentsBean.data;
                                    if(databean != null && databean.size()>0){
                                        data.addAll(databean);
                                        similarProfilePageFocusedAdapter.addItem(databean);
                                        if(flag){
                                            if(activitReleaseSimilarProfilePageFocusedXRecyclerView != null){
                                                activitReleaseSimilarProfilePageFocusedXRecyclerView.refreshComplete(); //TODO 下拉刷新完毕
                                            }

                                        }else{
                                            if(activitReleaseSimilarProfilePageFocusedXRecyclerView != null){
                                                activitReleaseSimilarProfilePageFocusedXRecyclerView.loadMoreComplete();  //TODO 上拉加载完毕
                                            }
                                        }
                                    }else{
                                        if(activitReleaseSimilarProfilePageFocusedXRecyclerView != null){
                                            activitReleaseSimilarProfilePageFocusedXRecyclerView.setNoMore(true);
                                        }
                                    }
                                    //similarProfilePageFocusedAdapter.notifyDataSetChanged();
                                }else{
                                    Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,postCommentsBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc  收藏
     * @param po_id_01*/
    private void clickcollect(String po_id_01) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.COLLECT)
                .addParams("cus_id", user_id)
                .addParams("po_id", po_id_01)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse===333=========>"+praiseParseNetworkResponse);
                        final ClickcollectBean clickcollectBean = gson.fromJson(praiseParseNetworkResponse,ClickcollectBean.class);
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    if(clickcollectBean.errorCode == 200 ){
                                        // TODO  改变收藏的图标和数据
                                        if(clickcollectBean.errorMessage.equals("收藏成功!")){
                                            lCount = lCount+1;
                                            activitReleaseSimilarProfilePageFocusedTvFavoriteBumber.setText(lCount+"");
                                            activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang_01);
                                        }else if(clickcollectBean.errorMessage.equals("取消收藏!")){
                                            lCount = lCount -1;
                                            activitReleaseSimilarProfilePageFocusedTvFavoriteBumber.setText(lCount+"");
                                            activitReleaseSimilarProfilePageFocusedIvFavorite.setImageResource(R.mipmap.shou_cang);
                                        }


                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,clickcollectBean.errorMessage,Toast.LENGTH_SHORT).show();
                                    }else{
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,clickcollectBean.errorMessage,Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 评论  {"errorCode":200,"errorMessage":"ok"}
     * @param etCommentariesContent*/
    private void submitComments(String etCommentariesContent) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.COMMENTS)
                .addParams("cus_id", user_id)
                .addParams("po_id", po_id)
                .addParams("content", etCommentariesContent)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                        // Log.e(TAG,"praiseParseNetworkResponse======555======>"+praiseParseNetworkResponse);
                        final CommentsBean commentsBean = gson.fromJson(praiseParseNetworkResponse,CommentsBean.class);
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {

                                    if(commentsBean.errorCode == 200 ){
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                        activitReleaseSimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                                        activitReleaseSimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                                        loadCommentsData(po_id,p);
                                    }else{
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,commentsBean.errorMessage,Toast.LENGTH_SHORT).show();
                                        activitReleaseSimilarProfilePageFocusedLlIsVisition.setVisibility(View.GONE);
                                        activitReleaseSimilarProfilePageFocusedLlCommentaries.setVisibility(View.VISIBLE);
                                    }
                                }
                            });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc 点赞
     * */
    private void giveLike() {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.PRAISE)
                .addParams("cus_id", user_id)
                .addParams("cat_id", cat_id)
                .addParams("po_id", po_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse======555======>"+praiseParseNetworkResponse);
                        final PraiseBean praiseBean =  gson.fromJson(praiseParseNetworkResponse,PraiseBean.class);
                        MyApplication.getmHandler().post(new Runnable() {
                            @Override
                            public void run() {
                                if(praiseBean.errorCode == 200){
                                    if(praiseBean.errorMessage.equals("点赞成功!")){
                                        if(hits_like >= 0){
                                            hits_like = hits_like +1;
                                        }
                                        lstate1 =1;
                                        activitReleaseSimilarProfilePageFocusedTvPraiseBumber.setText(hits_like+"");
                                        activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_10);
                                        EventBus.getDefault().post(new EventZanBean(posts_deleted,posts_deleted_id,hits_like,lstate1));
                                    }else if(praiseBean.errorMessage.equals("点赞取消!")){
                                        if(hits_like >= 1){
                                            hits_like = hits_like - 1;
                                        }
                                        lstate1 =0;
                                        activitReleaseSimilarProfilePageFocusedTvPraiseBumber.setText(hits_like+"");
                                        activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_05);
                                        EventBus.getDefault().post(new EventZanBean(posts_deleted,posts_deleted_id,hits_like,lstate1));
                                    }
                                }else{
                                    Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,praiseBean.errorMessage,Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc 删除帖子
     * */
    private void tipOffPost() {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.DELET_POST)
                .addParams("po_id", po_id)
                .addParams("cus_id", user_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                       // Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final TipOffPostBean tipOffPostBean =  gson.fromJson(parseNetworkResponse,TipOffPostBean.class);
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    if(tipOffPostBean.errorCode == 200){

                                        if(flag_01){  // todo 删除自己的帖子
                                            EventBus.getDefault().post(new EventBusBean(posts_deleted,posts_deleted_id));
                                            Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"删除成功",Toast.LENGTH_LONG).show();
                                        }else{ //todo 管理员删除别人的帖子  要去通知刷新界面
                                            Log.e(TAG,"praiseParseNetworkResponse===222=要去通知刷新界面===todo====>");
                                            EventBus.getDefault().post(new deleteOthersBean(posts_deleted));
                                            Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"已删除别人的帖子",Toast.LENGTH_LONG).show();
                                        }
                                        finish();
                                        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                                        popupWindow.dismiss();
                                    }else if(tipOffPostBean.errorCode == 66){
                                        flag_01 = true;
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,tipOffPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                    }else{
                                        flag_01 = true;
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,tipOffPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                    }
                                }
                            });

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        flag_01 = true;
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }
                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc 举报帖子
     * @param po_id
     * @param content*/
    private void exposePost(String po_id, String content) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.EXPOSE_POST)
                .addParams("po_id",po_id)
                .addParams("cus_id", user_id)
                .addParams("cat", content)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                       // Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final ExposePostBean exposePostBean =   gson.fromJson(parseNetworkResponse,ExposePostBean.class);
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    if(exposePostBean.errorCode == 200){
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"举报成功",Toast.LENGTH_LONG).show();
                                    }else{
                                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,exposePostBean.errorMessage,Toast.LENGTH_LONG).show();
                                    }

                                }
                            });

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Toast.makeText(ReleaseSimilarProfilePageFocusedActivity.this,"网络异常",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    private void showDialog() {
        DialogUtil.showItemSelectDialog(ReleaseSimilarProfilePageFocusedActivity.this, mWidth
                , onIllegalListener
                , "色情/辱骂"
                , "广告骚扰"
                , "政治"
                , "其他");//可填添加任意多个Item呦
    }
    /**
     * @desc 分享
     * */
    private void share() {
        popupWindow = new PopupWindow(this);
        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(this).inflate(R.layout.layout_similar_profile_page_focused_popupwindow_style,null);
        findSharePopupWindow(view);
        popupWindow.setContentView(view);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setOutsideTouchable(false);
        popupWindow.setFocusable(true);
        popupWindow.setAnimationStyle(R.style.anim_menu_bottombar);
        View rootview = View.inflate(this,R.layout.activit_release_similar_profile_page_focused,null);
        popupWindow.showAtLocation(rootview,  Gravity.BOTTOM,0,0);

    }
    /**
     * @desc 查找分享的控件
     * */
    private void findSharePopupWindow(View view) {
        ll_wei_xin = (LinearLayout) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_ll_wei_xin);
        ll_qq = (LinearLayout) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_ll_qq);
        ll_wei_bo = (LinearLayout) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_ll_wei_bo);
        ll_tip_off = (LinearLayout) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_ll_tip_off);
        ll_delect = (LinearLayout) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_ll_delect);
        tv_cancel = (TextView) view.findViewById(R.id.layout_similar_profile_page_focused_popupwindow_style_tv_cancel);

        ll_wei_xin.setOnClickListener(this);
        ll_qq.setOnClickListener(this);
        ll_wei_bo.setOnClickListener(this);
        ll_tip_off.setOnClickListener(this);
        ll_delect.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);

    }

    /**
     * @desc 查找头部布局控件
     * */
    private void findHeaderView(View header) {
        header_recyclerView = (RecyclerView) header.findViewById(R.id.fragment_similar_profile_page_focused_header_RecyclerView);
        SimilarProfilePageFocusedHeaderBean  similarProfilePageFocusedHeaderBean = new SimilarProfilePageFocusedHeaderBean(po_id,po_name,addtime,video,vpic,content,cat_id,cus_id,cus_name,cus_logo,hits_like,lstate,col,state,count,lCount,datalist);
        LinearLayoutManager layoutManager =   new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        header_recyclerView.setLayoutManager(layoutManager);
        ReleaseSimilarProfilePageFocusedHeaderAdapter   releaseSimilarProfilePageFocusedHeaderAdapter = new ReleaseSimilarProfilePageFocusedHeaderAdapter(this,similarProfilePageFocusedHeaderBean);
        header_recyclerView.setAdapter(releaseSimilarProfilePageFocusedHeaderAdapter);
    }
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }

//    @Subscribe(threadMode = MAIN,sticky = true)
//    public void StickyEvent(GiveLikeEventBean event){
//       if(event.getLstate() == 0 ){
//           activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_05);
//       }else{
//           activitReleaseSimilarProfilePageFocusedIvPraise.setImageResource(R.mipmap.zan_10);
//       }
//        activitReleaseSimilarProfilePageFocusedTvPraiseBumber.setText(event.getThumbUpNumber()+"");
//    }
}
